package com.freight.msg.controller;

import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.msg.dto.MsgCustCategoryDto;
import com.freight.msg.dto.MsgCustMessSaveDto;
import com.freight.msg.entity.MsgCustCategory;
import com.freight.msg.entity.MsgCustMess;
import com.freight.msg.service.MsgCustMessService;
import com.freight.msg.vo.MsgCustMessVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "自助问答管理接口")
@RequestMapping("/freight/msgCustMess")
@Transactional
public class MsgCustMessController {

    @Autowired
    private MsgCustMessService msgCustMessService;

    @RequestMapping(value = "/getMsgCustMessId", method = RequestMethod.POST)
    @ApiOperation(value = "根据id获取文件")
    public Result<MsgCustMessVo> getMsgCustMessId(Long id) {
        MsgCustMessVo platformRules=msgCustMessService.getMsgCustMessId(id);
        return new ResultUtil<MsgCustMessVo>().setData(platformRules);
    }

    @RequestMapping(value = "/getMsgCustCategoryList", method = RequestMethod.GET)
    @ApiOperation(value = "获取问答类目列表 --- 类型区分")
    public Result<Page<MsgCustCategory>> getMsgCustCategoryList( PageVo pageVo) {
        Page<MsgCustCategory> page = msgCustMessService.getMsgCustCategoryList(PageUtil.initPage(pageVo));
        return new ResultUtil<Page<MsgCustCategory>>().setData(page);
    }

    @RequestMapping(value = "/platformMsgCustCategoryList", method = RequestMethod.GET)
    @ApiOperation(value = "获取问答类目列表")
    public Result<Page<MsgCustCategory>> platformMsgCustCategoryList( PageVo pageVo) {
        Page<MsgCustCategory> page = msgCustMessService.platformMsgCustCategoryList(PageUtil.initPage(pageVo));
        return new ResultUtil<Page<MsgCustCategory>>().setData(page);
    }

    @RequestMapping(value = "/getMsgCustMessIdList", method = RequestMethod.GET)
    @ApiOperation(value = "根据类目id获取问答内容")
    public Result<Page<MsgCustMess>> getMsgCustMessIdList(Long msgCustCategoryId, PageVo pageVo) {
        Page<MsgCustMess> list = msgCustMessService.getMsgCustMessIdList(msgCustCategoryId , PageUtil.initPage(pageVo));
        return new ResultUtil<Page<MsgCustMess>>().setData(list);
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "获取问答内容列表")
    public Result<Page<MsgCustMess>> getByCondition(PageVo pageVo) {
        Page<MsgCustMess> page = msgCustMessService.findByCondition( PageUtil.initPage(pageVo));
        return new ResultUtil<Page<MsgCustMess>>().setData(page);
    }

    @RequestMapping(value = "/saveMsgCustCategory", method = RequestMethod.POST)
    @ApiOperation(value = "保存问答类目")
    public Result<String> saveMsgCustCategory(MsgCustCategoryDto msgCustCategoryDto) {
        msgCustMessService.saveMsgCustCategory(msgCustCategoryDto);
        return new ResultUtil<String>().setData("保存成功");
    }

    @RequestMapping(value = "/saveMsgCustMess", method = RequestMethod.POST)
    @ApiOperation(value = "保存问答内容")
    public Result<String> saveMsgCustMess(@RequestBody String content) {
        msgCustMessService.saveMsgCustMess(content);
        return new ResultUtil<String>().setData("保存成功");
    }

    @RequestMapping(value = "/deleteMsgCustCategory", method = RequestMethod.POST)
    @ApiOperation(value = "删除问答类目")
    public Result<String> deleteMsgCustCategory(Long msgCustCategoryId) {
        msgCustMessService.deleteMsgCustCategory(msgCustCategoryId);
        return new ResultUtil<String>().setData("操作成功");
    }

    @RequestMapping(value = "/deleteMsgCustMess", method = RequestMethod.POST)
    @ApiOperation(value = "删除问答内容")
    public Result<String> deleteMsgCustMess(Long msgCustMessId) {
        msgCustMessService.deleteMsgCustMess(msgCustMessId);
        return new ResultUtil<String>().setData("操作成功");
    }

    //-----------------------------------------------------------------------------------------------------------------

//    @RequestMapping(value = "/genCustMess", method = RequestMethod.POST)
//    @ApiOperation(value = "生成客诉信息")
//    public Result<String> genCustMess(MsgCustMessDto msgCustMessDto) {
//
//        msgCustMessService.genCustMess(msgCustMessDto);
//        return new ResultUtil<String>().setData("投诉成功");
//    }
//
//    @RequestMapping(value = "/replyCustMess", method = RequestMethod.POST)
//    @ApiOperation(value = "回复客诉信息")
//    public Result<String> replyCustMess(MsgCustMessReplayDto msgCustMessDto) {
//        msgCustMessService.replayCustMess(msgCustMessDto);
//        return new ResultUtil<String>().setData("投诉成功");
//    }
}